import java.util.HashSet;
import java.util.Set;

/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 016. 不含重复字符的最长子字符串
 * @author: WXY
 * @create: 2022-12-22 17:59
 * @Version 1.0
 **/

public class offer_five3_lengthOfLongestSubstring {
    public static int lengthOfLongestSubstring(String s) {
        int maxLen = 0;
        int len = s.length();
        int l = 0;
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < len; i++) {
            char c = s.charAt(i);
            while (set.contains(c)) {
                set.remove(s.charAt(l++));
            }
            set.add(c);
            maxLen = Math.max(maxLen, i - l + 1);
        }
        return maxLen;
    }
}
